//
//  YSRegisterCtrl.m
//  Yueshi
//
//  Created by Northwan on 15/7/24.
//  Copyright (c) 2015年 悦食中国. All rights reserved.
//  注册

#import "YSRegisterCtrl.h"
#import "YSMineDataTool.h"
#import "YSModifyInfoCtrl.h"

@interface YSRegisterCtrl ()
@property (weak, nonatomic) IBOutlet UITextField *pwdTextField;
@property (weak, nonatomic) IBOutlet UITextField *phoneTextField;
@property (strong, nonatomic) UIImageView *bgImgView;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;

@end

@implementation YSRegisterCtrl

- (void)viewDidLoad {
    [super viewDidLoad];
    self.fd_prefersNavigationBarHidden  = YES;
    _bgImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0, SCREENW, SCREENH)];
    [self.view insertSubview:_bgImgView belowSubview:self.scrollView];
    if(SCREENH==480){// 4s 4
        self.bgImgView.image = [UIImage imageNamed:@"bg_login_4.jpg"];
    }else if(SCREENH==568){// 5s 5
        self.bgImgView.image = [UIImage imageNamed:@"bg_login_5.jpg"];
    }else if(SCREENH==667){// 6
        self.bgImgView.image = [UIImage imageNamed:@"bg_login_6.jpg"];
    }else if(SCREENH==736){// 6 plus
        self.bgImgView.image = [UIImage imageNamed:@"bg_login_6p.jpg"];
    }
    
    [UIUtil dealPlaceHolderColor:self.phoneTextField color:[UIColor whiteColor]];
    [UIUtil dealPlaceHolderColor:self.pwdTextField color:[UIColor whiteColor]];
    self.phoneTextField.tintColor = [UIColor whiteColor];
    self.pwdTextField.tintColor = [UIColor whiteColor];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(back:) name:kUpdateMineInfoNortif object:nil];
}

-(BOOL)shouldStatusBarLightContent{
    return YES;
}

-(void)back:(NSNotification *)nortif{
     [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)tapAction:(UIButton *)sender {
    switch (sender.tag) {
        case 0://返回
            [self.navigationController popViewControllerAnimated:YES];
            break;
        case 1://注册title
            ShowTips(@"点你妹啊");
            break;
        case 2:{//确定
            if(ISBLANK(self.phoneTextField.text)){
                ShowTips(@"手机号为空");
                return;
            }
            if(ISBLANK(self.pwdTextField.text)){
                ShowTips(@"密码为空");
                 return;
            }
            if(!self.phoneTextField.text.isValidatePhone){
                ShowTips(@"非法手机号");
                return;
            }
            
            [YSMineDataTool registerWithParams:self.phoneTextField.text password:self.pwdTextField.text success:^(YSRegisterRes *result) {
                if(result.isSucc){
                    [result saveInfo];
                    [result saveUserInfo];
                    [[NSNotificationCenter defaultCenter]postNotificationName:kUpdateMineInfoNortif object:nil];
                    [[NSNotificationCenter defaultCenter]postNotificationName:kRegistFinishToModifyInfoNortif object:nil];
                }else{
                    ShowEnterTips(result.data);
                }
            } failure:^(NSError *error) {
                ShowTips(kRequestFailure);
            }];
            break;
        }
        default:
            break;
    }
}

- (IBAction)tapCover:(id)sender {
    [self.view endEditing:YES];
}

-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:kUpdateMineInfoNortif object:nil];
}


@end
